﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Rockfan.Framework.Entities;
using Rockfan.Framework.Entities.Interfaces;

namespace Rockfan.Framework.Audio
{
    public sealed class Song : IEntity
    {
        #region Properties

        public string Name { get; private set; }
        public float TimeCreated { get; private set; }

        public List<AudioTrack> Tracks { get; private set; }

        #endregion

        #region Methods

        public Song(string name)
        {
            this.Name = name;
            this.TimeCreated = EngineServices.TotalGameTime;
            Tracks = new List<AudioTrack>();
        }

        public void Play()
        {
            foreach (var item in Tracks)
                item.Play();
        }

        public void Stop()
        {
            foreach (var item in Tracks)
                item.Stop();
        }

        public void Pause()
        {
            foreach (var item in Tracks)
                item.Pause();
        }

        public void SyncTracks(ref AudioTrack track)
        {
            var position = track.Playposition;

            foreach (var item in Tracks)
                item.Playposition = position;
        }

        public AudioTrack CreateTrack(string fileLocation)
        {
            if (System.IO.File.Exists(fileLocation))
            {
                var track = new AudioTrack(fileLocation);
                Tracks.Add(track);
                return track;
            }

            return default(AudioTrack);
        }

        #endregion
    }
}
